package week11;

import java.util.Arrays;
import java.util.Scanner;

class ArrayUtils {

	public static double findMax(double[] arr, int begin, int end) {
		Double Max = 0.0;
		if (arr == null ) {
			throw new IllegalArgumentException("arr[]=null");
		}
		else if(begin>=end) {
			throw new IllegalAccessError("begin:"+ begin +">= end:" + end);
		}
		else if(begin<0) {
			throw new IllegalAccessError("begin:" +begin +"< 0");
			
		}
		else if(end>arr.length) {
			throw new IllegalAccessError("end:" +end+" > arr.length" );
		}
		else {
			int temp = 0;
			for (int i = begin; i <= end; i++) {
				if (arr[i] >= Max) {
					Max =  arr[i];
				}
			}

		}
		return Max;
	}

}



public class PTA730603 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		double[] arr = new double[n];
		String str = null;
		Scanner sc = new Scanner(System.in);
		for(int i=0;i<n;i++) {
			int a=sc.nextInt();
			arr[i]=a;
		}
		while (sc.hasNextInt()) {
			int begin=sc.nextInt();
			int end=sc.nextInt();
			//System.out.println(ArrayUtils.findMax(arr, end, end));
			try {
			     ArrayUtils.findMax(arr, begin, end);
			} catch (Exception e1) {
				
				System.out.println(e1);
			}
			
		}
	}

}





